import pymysql

MYSQL_HOST = "127.0.0.1"
MYSQL_USER = "root"
MYSQL_PSW = "123456"

if __name__ == '__main__':
    for db_clone in ('a', 'b', 'c', 'd', 'e', 'f'):
        MYSQL_DB = f"by3_clone_{db_clone}"
        db = pymysql.connect(host=MYSQL_HOST, user=MYSQL_USER, password=MYSQL_PSW, database=MYSQL_DB)
        cursor = db.cursor()
        sql_command = "INSERT INTO strategies (id, category, name, on_off, parameters) VALUES (%s, %s, %s, %s, %s)"


        def s48_s87():
            for sid in range(48, 48 + 40):
                values = (sid,
                          '买',
                          '策略1的克隆',
                          0,
                          '{"不交易时间段":[6,7, 23, 24],"每小时开始生效时刻(分钟)": 1,"在指定ema下不买入": 55,"本条蜡烛未发生过卖出操作才买入": false,"x0": 3,"x1": 5,"x2": 8,"k1": 46,"k2": 88,"n": 4, "不交易时间段(秒)": [0, 10], "蜡烛周期内最大操作次数": 1}')
                cursor.execute(sql_command, values)


        def s88_s93(start=88, clone_number=6):
            for sid in range(start, start + clone_number):
                values = (sid, '卖',
                          '策略21的克隆',
                          0,
                          '{"x0": 0,"x1": 0, "k线":"3m", "时间范围及xi":[[10, 20, 5], [150, 170, 6]]}');
                cursor.execute(sql_command, values)


        def s95_p10():
            for sid in range(95, 95 + 10):
                values = (sid,
                          '买',
                          '策略1的克隆',
                          0,
                          '{"不交易时间段":[6,7, 23, 24],"每小时开始生效时刻(分钟)": 1,"在指定ema下不买入": 55,"本条蜡烛未发生过卖出操作才买入": false,"x0": 3,"x1": 5,"x2": 8,"k1": 46,"k2": 88,"n": 4, "不交易时间段(秒)": [0, 10], "蜡烛周期内最大操作次数": 1}')
                cursor.execute(sql_command, values)


        def s110_p4(start=110, pieces=4):
            for sid in range(start, start + pieces):
                values = (sid,
                          '买',
                          '策略5的克隆',
                          0,
                          '{"不交易时间段":[6, 8], "ema列表":[3, 5, 8], "条件1on_off":0, "条件2on_off":0, "撤单on_off":0, "计算A所用k线":"3m", "x":0}')
                cursor.execute(sql_command, values)


        def s105_p1(start=105, pieces=1):
            for sid in range(start, start + pieces):
                values = (sid,
                          '买',
                          '敏捷需求321',
                          0,
                          '{"不交易时间段":[6, 8], "条件0on_off":0, "n":0, "条件1on_off":0, "ema列表":[3, 5, 8], "条件2on_off":0, "撤单on_off":0, "计算A所用k线":"3m", "x":0, "条件4on_off":0, "条件4指定k线":"3m", "Q":1, "马上撤单on_off":0, "条件7on_off":0, "条件7指定k线":"3m"}')
                cursor.execute(sql_command, values)


        def s114_p1(start=114, pieces=1):
            for sid in range(start, start + pieces):
                values = (sid,
                          '卖',
                          '敏捷需求322',
                          0,
                          '{"生效时间段":[6, 8], "条件1on_off":0, "指定k线":"3m", "ema列表":[3, 5, 8], "N":40, "Q":60, "Y":0.0005, "G":0.0005, "h":0, "k、X、E列表":[[10, 20, 10],[20, 20, 30]]}')
                cursor.execute(sql_command, values)


        def s115_p1(start=115, pieces=1):
            for sid in range(start, start + pieces):
                values = (sid,
                          '自动化',
                          '策略组测试',
                          0,
                          '{"统计时长":"day", "分组":[[1,2,3], [4,5,6]]}')
                cursor.execute(sql_command, values)


        def s200_p1(start=200, pieces=1):
            for sid in range(start, start + pieces):
                values = (sid,
                          '卖',
                          '强制卖出',
                          0,
                          '')
                cursor.execute(sql_command, values)


        def s201_p1(start=201, pieces=1):
            for sid in range(start, start + pieces):
                values = (sid,
                          '自动化',
                          '当前价格大于p+x，则把关联策略的N参数修改为z，修改持续u秒',
                          0,
                          '{"关联策略":114, "u":10, "xz列表":[[1,2], [3,4]}')
                cursor.execute(sql_command, values)


        # s48_s87()
        # s88_s93()
        # s95_p10()
        # s88_s93(start=106, clone_number=4)
        # s110_p4()
        # s105_p1()
        # s114_p1()
        # s115_p1()
        # s200_p1()
        s201_p1()
        db.commit()
        db.close()
